package jtk.project4.fleet.ibatis.dao;

import java.sql.SQLException;
import java.util.List;

import jtk.project4.fleet.domain.RbItem;

public class RbItemDao extends IbatisDao{
	
	public List selectRbItem() throws SQLException {
		return getSqlMap().queryForList("SELECT_ALL_RBITEM", null);
	}
	
	public RbItem selectRbItemByID(int itemId) throws SQLException {
		return (RbItem) getSqlMap().queryForObject("SELECT_RBITEM_BY_ID", itemId);
	}

	public int deleteRbItem(RbItem rbitem) throws SQLException {
		return (int) getSqlMap().delete("DELETE_RBITEM", rbitem);
	}
	
	public int updateRbItem(RbItem rbitem) throws SQLException {
		return (int) getSqlMap().update("UPDATE_RBITEM", rbitem);
	}
	
	public RbItem insertRbItem(RbItem rbitem) throws SQLException {
		return (RbItem) getSqlMap().insert("INSERT_RBITEM", rbitem);
	}

	public static void main (String args[]) throws SQLException {
		RbItem rbitem = new RbItem();
		List<RbItem> list;
		
		list = new RbItemDao().selectRbItem();
		System.out.println(list.size());
		rbitem = new RbItemDao().selectRbItemByID(28);
		System.out.println(rbitem.getName());
		
		rbitem.setItemId(25);
		//rbitem.setName("Ihsan Helmi");
		//new RbItemDao().insertRbItem(rbitem);
		new RbItemDao().deleteRbItem(rbitem);
		//new RbItemDao().updateRbItem(rbitem);
	}	
}